//
//  DownloadCell.m
//  IntegralDog
//
//  Created by User on 16/1/22.
//  Copyright © 2016年 hanen. All rights reserved.
//

#import "DownloadCell.h"
#import "AppDelegate.h"
#import "Macro.h"
@implementation DownloadCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.clipsToBounds = YES;
        CGFloat width = [[[NSUserDefaults standardUserDefaults] objectForKey:@"width"] floatValue];
        _TitleImage = [[UIImageView alloc] initWithFrame:CGRectMake1(16, 6, 42, 42)];
        _TitleImage.layer.cornerRadius = 10;
        _TitleImage.layer.masksToBounds = YES;
        _AppName = [[UILabel alloc] initWithFrame:CGRectMake2(72, 3, 227, 21)];
        _AppName.tag = 0;
        _typeLab = [[UILabel alloc] initWithFrame:CGRectMake2(72, 16, 28, 21)];
        //_typeLab.text = @"工具";
        _typeLab.tag = 1;
        
        _DownCount = [[UILabel alloc] initWithFrame:CGRectMake2(117, 31, 109, 10)];
        //_DownCount.text = @"(剩余下载量3555次)";
        _DownCount.tag = 2;
        _jifenBg = [[UIImageView alloc] initWithFrame:CGRectMake2(260, 16, 44, 20)];
        _jifenBg.image = [UIImage imageNamed:@"Btn_Normal_Jifendi.png"];
        _moneyPic = [[UIImageView alloc] initWithFrame:CGRectMake2(268, 24, 7, 7)];
        _moneyPic.image = [UIImage imageNamed:@"Btn_Normal_Jifen 2"];
        _jifen = [[UILabel alloc] initWithFrame:CGRectMake2(277, 22, 34, 11)];
        //_jifen.text = @"1000";
        _jifen.tag = 3;
        _jifen.textColor = [UIColor whiteColor];
        _DownCount.textColor = fontLightGrayColor;
        _typeLab.textColor = fontLightGrayColor;
        [self setFontLabel:_AppName byscale:width];
        [self setFontLabel:_typeLab byscale:width];
        [self setFontLabel:_DownCount byscale:width];
        [self setFontLabel:_jifen byscale:width];
        [self.contentView addSubview:self.TitleImage];
        [self.contentView addSubview:self.AppName];
        [self.contentView addSubview:self.typeLab];
        [self.contentView addSubview:self.DownCount];
        [self.contentView addSubview:self.jifenBg];
        [self.contentView addSubview:self.jifen];
        [self.contentView addSubview:self.moneyPic];
        
    };
    return self;
}

- (void)star:(int)starClass
{
    for (int i = 0; i < 5; i ++) {
        _xing = [[UIImageView alloc] initWithFrame:CGRectMake1(72+8*i, 33, 7, 7)];
        _xing.image = [UIImage imageNamed:@"Btn_Normal_Xingxingb.png"];
        _xing.tag = i;
        if (_xing.tag < starClass) {
            _xing.image = [UIImage imageNamed:@"Btn_Normal_Xingxinga.png"];
        }
        [self.contentView addSubview:_xing];
    }
}

- (void)setFontLabel:(UILabel *)label  byscale:(CGFloat )width
{

    int size;
    if (width == 1) {
        size = 13;
    }
    else if (width >1&&width <1.29) {
        size = 14;
    }
    else
    {
        size = 15;
    }
    if (label.tag == 0) {
        [label setFont:[UIFont systemFontOfSize:size]];

    }
    else
    {
    [label setFont:[UIFont systemFontOfSize:size-4]];
    }
}


CG_INLINE CGRect
CGRectMake2(CGFloat x,CGFloat y,CGFloat width,CGFloat height)
{
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    return CGRectMake(x * app.autoSizeScaleX, y * app.autoSizeScaleY, width * app.autoSizeScaleX, height * app.autoSizeScaleY);
}
CG_INLINE CGRect
CGRectMake1(CGFloat x,CGFloat y,CGFloat width,CGFloat height)
{
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    return CGRectMake(x * app.autoSizeScaleX, y * app.autoSizeScaleY, width * app.autoSizeScaleX, height * app.autoSizeScaleX);
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
